export const responseJson = (code:number, data: any = null)=>{
  return {
    code:code,
    data:data
  };
}

export const getLoginUid = (event:any) => {
  return event.context.auth ? event.context.auth.uid : 0;
}

//获取当前时间
export const getTitle = () => {
  const currentDate = new Date();
  const year = currentDate.getFullYear();
  const month = ("0"+(currentDate.getMonth()+1)).slice(-2);
  const day =  ("0"+currentDate.getDay()).slice(-2);
  return year+"-"+month+"-"+day;
}

//截取文章
export const trimMarkdown = (content: string, maxLength: number) => {
  let strippedContent = content.replace(/#|\*|_|`/g, '');
  if (strippedContent.length > maxLength) {
      strippedContent = strippedContent.substr(0,maxLength) + '...';
  }
  return strippedContent;
}
//获取文章第一张图片
export const headCover = (content: string) => {
  const regex = /!\[.*\]\((.*)\)/;
  const match = content.match(regex);
  if (match) {
      return match[1];
  }
  return null;
}